package com.itheima;

public class ArrayDemo5 {
    public static void main(String[] args) {
        //目标:二维数组的认识
        printArray();
        printArray2();
    }

    public static void printArray(){
        String[][] classroom = {        //静态二维数组
                {"绽放无极","赵敏","周弱智"},        //第一排
                {"张三丰","宋远桥","殷梨亭"},        //第二排
                {"灭绝师太","陈坤","玄冥二老","金毛狮王"},
                {"杨晓","纪晓芙"}
        };

        //数组名[行索引]
        String[] names=classroom[2];
        for (int i = 0; i < names.length; i++) {
            System.out.println(names[i]);
        }

        //数组名[行索引][列索引]
        System.out.println(classroom[1][1]);

        //长度访问:数组名.length  就是行数
        System.out.println(classroom.length);
        System.out.println(classroom[2].length);

        //动态初始化数组
        int[][] arr=new int[3][5];  //动态数组,3行5列
    }

    //遍历二维数组
    public static void printArray2(){
        String[][] classroom = {        //静态二维数组
                {"绽放无极","赵敏","周弱智"},        //第一排
                {"张三丰","宋远桥","殷梨亭"},        //第二排
                {"灭绝师太","陈坤","玄冥二老","金毛狮王"},
                {"杨晓","纪晓芙"}
        };

        for (int i = 0; i < classroom.length; i++) {
            String[] names=classroom[i];
            for (int j = 0; j < names.length; j++) {
                System.out.println(names[j]+" ");
            }
            System.out.println();
        }

        System.out.println("--------------------------------");

        //也可把name代替
        for (int i = 0; i < classroom.length; i++) {
            for (int j = 0; j < classroom[i].length; j++) {
                System.out.println(classroom[i][j]);
            }
        }

    }
}
